package com.atguigu.gmall.item.service.config;

import jodd.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-11 21:28
 */
@Configuration
public class ThreadPoolConfig {

	/**
	 * 创建了一个线程池 并注入到ioc容器
	 */
	@Bean
	public ThreadPoolExecutor threadPoolExecutor() {
		return new ThreadPoolExecutor(2, 5, 3L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3),
				new ThreadFactoryBuilder().setNameFormat("fxz-thread-pool-%d").get());
	}

}
